<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
	<%@ include file="/WEB-INF/pages/weixin/include/title.jsp"%>
    <%@ include file="/WEB-INF/pages/weixin/include/include.jsp"%>
    
	<script src="${root}/res/jsLib/jquery/jquery-1.11.1.min.js"></script>
	<script src="${root}/res/jsLib/Validform_v5.3.2_min.js"></script>
	<script src="${root}/res/jsLib/ValidformExp.js"></script>
    
    <script type="text/javascript">
    	
    	var vf;
	    $(function(){
	    	wxUtils.showToast();
	    	wxUtils.loadDicData({
	    		urlFun:function(){
	    			return JSON.stringify({"method":"orgentinfo","id":'${user.userid}'});
	    		},
	    		showFun:function(data){
	    			wxUtils.closeToast();
	    			if(data.datalist.length>0){
	    				var u = data.datalist[0];
	    				var form = $("#userForm");
	    				form.find("input[name=orgId]").val(u['ID']);
	    				form.find("input[name=email]").val(u['EMAIL']);
	    				form.find("input[name=orgName]").val(u['ORG_NAME']);
	    				form.find("input[name=orgArea2]").val(u['ORG_AREA2']);
						$("#industry1").val(u['INDUSTRY1']);
						$("#industry2").val(u['INDUSTRY2']);
						$("#industry3").val(u['INDUSTRY3']);
						$("#industry4").val(u['INDUSTRY4']);
						
	    				wxUtils.loadDicData({
	    		    		urlFun:function(){
	    		    			return JSON.stringify({"method":"area1",'id':'441600'});
	    		    		},
	    		    		showFun:function(d1){
	    		    			for(var i=0; i<d1.datalist.length; i++){
	    		    				var trem = d1.datalist[i];
	    		    				if(trem['AREA_CODE']==u['ORG_AREA2']){
	    		    					$("#orgArea2").html("河源市-"+trem['AREA_NAME']);
	    		    					break;
	    		    				}
	    		    			}
	    		    		}
	    		    	});
	    				
	    				industry1();
	    				
	    				vf = $("#userForm").validform();
	    		    	
	    		    	$("#submitBtn").bind("click",function(){
	    		    		if(vf.check()){
	    		    			wxUtils.showToast("正在提交");
	    			    		$.post(wxUtils.ctx+"/weixin/enterprise/register.do",$("#userForm").serialize(),function(data){
	    			    			wxUtils.closeToast();
	    			    			if(data.success){
	    			    				wxUtils.msg("修改用户信息成功",1,function(){
	    			    					
	    			    				});
	    			    			}else{
	    			    				wxUtils.msg("修改用户信息时出现异常，请稍后再修改",2);
	    			    			}
	    			    		},'json');
	    		    		}
	    		    	});
	    				
	    			}else{
	    				wxUtils.msg("加载个人基本信息失败，请稍后重试。",2,function(){
	    					window.location.href = wxUtils.ctx + "/weixin/login.do";
	    				});
	    			}
	    		}
	    	});
	    	
	    	$("#returnBtn").click(function(){
	    		window.location.href = wxUtils.ctx + "/weixin/login.do"; 
			});
	    	
	    	wxUtils.iniScrollBar();
	    });
	    
	    function industry1(){
	    	var form = $("#userForm");
	    	var def = $("#industry1");
	    	var industry = form.find("select[name='industry1']");
	    	if(industry.length>0){
	    		industry.empty();
	    		form.find("select[name='industry2']").empty();
	    		form.find("select[name='industry3']").empty();
	    		form.find("select[name='industry4']").empty();
		    	wxUtils.loadDicData({
		    		urlFun:function(){
		    			return JSON.stringify({"method":"industry"});
		    		},
		    		showFun:function(data){
		    			var flag = false;
		    			industry.append("<option value=''>--请选择--</option>");
		    			for(var i=0; i<data.datalist.length; i++){
		    				var trem = data.datalist[i];
		    				var selected = '';
		    				if(def.val()==trem['INDUSTRY_CODE']){
		    					selected='selected="selected"';
		    					flag=true;
		    				}
		    				industry.append("<option "+selected+" value='"+trem['INDUSTRY_CODE']+"'>"+trem['INDUSTRY_NAME']+"</option>");
		    			}
		    			if(flag){
		    				industry.trigger("change");
		    				def.val('');
		    			}
		    		}
		    	});
	    	}
	    }
	    
	    function industry234(i,parent){
	    	var form = $("#userForm");
	    	var id = $(parent).val();
	    	var industry = form.find("select[name='industry"+i+"']");
	    	var def = $("#industry"+i);
	    	if(industry.length>0 && $.trim(id)!=''){
	    		industry.empty();
	    		if(i<3){
	    			var temp = form.find("select[name='industry3']")
	    			temp.empty();
	    			temp.append("<option value=''>--请选择--</option>");
	    		}
	    		if(i<4){
	    			var temp = form.find("select[name='industry4']")
	    			temp.empty();
	    			temp.append("<option value=''>--请选择--</option>");
	    		}
	    		wxUtils.loadDicData({
		    		urlFun:function(){
		    			return JSON.stringify({"method":"industry234","id":id});
		    		},
		    		showFun:function(data){
		    			var flag = false;
		    			industry.append("<option value=''>--请选择--</option>");
		    			for(var i=0; i<data.datalist.length; i++){
		    				var trem = data.datalist[i];
		    				var selected = '';
		    				if(def.val()==trem['INDUSTRY_CODE']){
		    					selected='selected="selected"';
		    					flag=true;
		    				}
		    				industry.append("<option "+selected+" value='"+trem['INDUSTRY_CODE']+"'>"+trem['INDUSTRY_NAME']+"</option>");
		    			}
		    			if(flag){
		    				industry.trigger("change");
		    				def.val('');
		    			}
		    		}
		    	});
	    	}else{
	    		industry.empty();
	    	}
	    }
	</script>
</head>
<body>
<div class="page" style="height: 100%;">
    <div class="page__bd">
    	<div class="weui-tab__panel detail_panel">
    		<div class="weui-panel__hd" id="returnBtn" style="cursor: pointer;left:0;padding-left: 0;" position="top">&lt 返回</div>
			<div position="center">
				<input type="hidden" id="industry1"/>
				<input type="hidden" id="industry2""/>
				<input type="hidden" id="industry3"/>
				<input type="hidden" id="industry4"/>
				<form id="userForm">
				<input type="hidden" name="userid" value="${user.userid }"/>
				<input type="hidden" name="username" value="${user.username }"/>
				<input type="hidden" name="orgArea1" value="441600"/>
				<input type="hidden" name="orgArea2"/>
				<input type="hidden" name="orgId"/>
				<div class="weui-cells weui-cells_form">
					<div class="weui-cells__title">账号信息</div>
		            <div class="weui-cell">
		                <div class="weui-cell__hd"><label class="weui-label">用户名</label></div>
		                <div class="weui-cell__bd">
		                    ${user.username }
		                </div>
		            </div>
		            
		            <div class="weui-cell">
		                <div class="weui-cell__hd"><label class="weui-label">密码</label></div>
		                <div class="weui-cell__bd">
		                    <input class="weui-input" type="password" name="password" dataType="*4-36" value="${user.password }"  placeholder="请输入密码"/>
		                </div>
		            </div>
		            
		            <div class="weui-cell">
		                <div class="weui-cell__hd"><label class="weui-label">确认密码</label></div>
		                <div class="weui-cell__bd">
		                    <input class="weui-input" type="password" dataType="*" recheck="password" value="${user.password }" placeholder="请再次输入密码"/>
		                </div>
		            </div>
		            
		             <div class="weui-cell">
		                <div class="weui-cell__hd"><label class="weui-label">E-mail</label></div>
		                <div class="weui-cell__bd">
		                    <input class="weui-input" type="text" name="email" dataType="e" placeholder="请输入E-mail"/>
		                </div>
		            </div>
		            
		            <div class="weui-cell">
		                <div class="weui-cell__hd"><label class="weui-label">企业名称</label></div>
		                <div class="weui-cell__bd">
		                    <input class="weui-input" type="text" name="orgName" dataType="*1-150" placeholder="请输入企业名称"/>
		                </div>
		            </div>
		            
		            <div class="weui-cell">
		                <div class="weui-cell__hd"><label class="weui-label">所属地区</label></div>
		                <div class="weui-cell__bd" id="orgArea2">
		                </div>
		            </div>
		            
		            <div class="weui-cell">
		                <div class="weui-cell__hd"><label class="weui-label">所属行业</label></div>
		                <div class="weui-cell__bd">
		                    <select class="weui-select" name="industry1" dataType="*" onchange="industry234(2,this)"><option value="">--请选择--</option></select>
		                    <select class="weui-select" name="industry2" dataType="*" onchange="industry234(3,this)"><option value="">--请选择--</option></select>
		                    <select class="weui-select" name="industry3" dataType="*" onchange="industry234(4,this)"><option value="">--请选择--</option></select>
		                    <select class="weui-select" name="industry4" dataType="*"><option value="">--请选择--</option></select>
		                </div>
		            </div>
		            
		             <div class="weui-btn-area">
			            <a id="submitBtn" class="weui-btn weui-btn_primary" href="javascript:void(0);" >保存修改</a>
			        </div>
		        </div>
		        </form>
			</div>
    	</div>
    </div>
</div>
</body>
</html>

